﻿@page "/xlsio/tables"
@inject Microsoft.JSInterop.IJSRuntime JS
@using System.IO;

@using Syncfusion.Blazor.Buttons
@*Hidden:Lines*@

@using BlazorDemos.Data.FileFormats.XlsIO

@*End:Hidden*@
@inherits SampleBaseComponent;

<SampleDescription>
  <p>This sample deomonstrates how to use tables in spreadsheets using XlsIO.</p>  
</SampleDescription>
<ActionDescription>
<p>Microsoft Office Excel 2007, Excel 2010 and Excel 2013 provides tables support that makes managing and analyzing data with ease and efficient. These tables come with specific style support.</p>
<p style='display: block'>XlsIO supports reading and writing tables in Excel 2007, Excel 2010 and Excel 2013 formats. Tables can be created from any input range of sheet data and the total row can be inserted into the table. Styles can also be applied to the tables.</p>
<p style='display: block'><b>Features:</b></p>
<ul>
<li>Adding tables to a spreadsheet</li>
<li>Advanced options of Excel tables such as Total Rows and Styles</li>
<li>Advanced options of Excel tables such as custom table style</li>
</ul>
</ActionDescription>

<div class="control-section">
    <p style="font-weight:normal">Click the button to view the Open Document Spreadsheet generated by Essential XlsIO. Please note that Microsoft Excel is required to view the resultant document.</p>

    <div class="checkbox-control">
        <div class="row">
            <SfCheckBox @bind-Checked=customStyle Label="Apply Custom Style" TChecked="bool"></SfCheckBox>
        </div>
    </div>
    <div class="button-section">
        <div id="button-control">
            <div class="row">
                <div>
                    <SfButton @onclick="TablesXlsIO">Create Document</SfButton>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .checkbox-control {
        margin: 5% 0 2% 0;
    }

    .control-section .row {
        margin: 10px 0;
    }
</style>

@code {
    MemoryStream excelStream;
    bool customStyle = false;

    /// <summary>
    /// Create and download the Excel document with table
    /// </summary>
    public async Task TablesXlsIO()
    {
        TablesService service = new TablesService();
        excelStream = service.TablesXlsIO(customStyle);
        await JS.SaveAs("Tables.xlsx", excelStream.ToArray());        
    }
}